/*
 * @Description: 报表表单
 * @Author: Zzt
 * @Date: 2022-11-08 10:16:49
 * @LastEditTime: 2022-11-14 10:22:16
 */
import { Form, Input, Select } from 'antd';
import { useReportTemplateContext } from '@/view/statistics/ReportTemplate/contexts/ReportTemplateContext';
import { IBaseDic } from '@/interfaces/global';
import { useEffect, useState } from 'react';
import { IAddReportTempParams } from '@/api/report';

export type IReportTempForm = Pick<IAddReportTempParams, 'name' | 'type' | 'remark'>;

interface IReportTempFormProps {
  tempTypeStr?: string;
  visible: boolean;
}

const ReportTempForm = (props: IReportTempFormProps) => {
  const { tempTypeStr, visible } = props;
  const { levelTempTypeList, selectFond, selectAT, selectLevel } = useReportTemplateContext();

  // 模板类型文案
  const [tempType, setTempType] = useState('');

  useEffect(() => {
    setTempType(`${selectFond.fondName}>${selectAT.atName}>${selectLevel.levelName}`);
  }, [visible]);

  return (
    <>
      <Form.Item label="模板类型">{tempTypeStr || tempType}</Form.Item>
      <Form.Item label="标题" name="name" rules={[{ required: true }]}>
        <Input placeholder="请填写模板标题" />
      </Form.Item>
      <Form.Item label="类型" name="type" rules={[{ required: true }]}>
        <Select
          options={levelTempTypeList.map((item: IBaseDic) => ({
            label: item.name,
            value: item.id
          }))}
        />
      </Form.Item>
      {/* <Form.Item label="数据映射关系" name="dataMapping" rules={[{ required: true }]}> */}
      {/*  <Select */}
      {/*    options={dataMappingList.map((item: IBaseDic) => ({ */}
      {/*      label: item.name, */}
      {/*      value: item.id */}
      {/*    }))} */}
      {/*  /> */}
      {/* </Form.Item> */}
      <Form.Item name="remark" label="模板说明">
        <Input.TextArea placeholder="备注信息描述，最多可填2000字" showCount maxLength={2000} />
      </Form.Item>
    </>
  );
};
export default ReportTempForm;
